<?php
// 添加mongodb数据库中
$mongo = include 'mongo.php';

// 修改
$title = trim($_GET['title']);

// 查询有没有条件，字段的显示问题
$where = ['title'=>$title];
$options = [
	//'projection' => ['title'=>1]
];

// 查询对象
$query = new MongoDB\Driver\Query($where, $options);
// 执行查询  一定要循环
$data = $mongo->executeQuery('php71.article', $query);

// 记录
$ret = $data->toArray()[0];



if (@$_POST['cnt']) {
	$bulk = new MongoDB\Driver\BulkWrite;
	$bulk->update(
		['title' => $title],
		['$set' => ['cnt' => $_POST['cnt']]],
		// 是否修改多条记录    没有时是否添加
		['multi' => true, 'upsert' => false]
	);
	$result = $mongo->executeBulkWrite('php71.article', $bulk);
	header('Location:index.php');
}



?>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>修改文章</title>
	<link rel="stylesheet" type="text/css" href="./static/css/bootstrap.min.css">
</head>
<body>
	<br>
	<div class="container">
		<form action="?title=<?php echo $title; ?>" method="POST" class="form-horizontal" role="form">

			<div class="form-group">
				<label class="col-sm-2 control-label">内容：</label>
				<div class="col-sm-10">
					<input type="text" name="cnt" class="form-control" value="<?php echo $ret->cnt; ?>">
				</div>
			</div>

			<div class="form-group">
				<div class="col-sm-10 col-sm-offset-2">
					<button type="submit" class="btn btn-primary">修改文章</button>
					<a href="index.php">返回</a>
				</div>
			</div>
		</form>
	</div>

	

	<script src="./static/js/jquery.min.js"></script>
	<script src="./static/js/bootstrap.min.js"></script>
</body>
</html>